home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS in a Box 7
/
BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso
/
Files
/
Tele
/
S
/
SetSoundVol.cpt
/
SetSoundVol RCMD.p
< prev
next >
Wrap
Text File
|
1991-03-03
|
12KB
|
396 lines
unit SetSoundVol;
{ White Knight RCMD to set the speaker volume. }
{ THINK Pascal 3.0.1 }
{ Aron Roberts }
{ Version 1.1, 3 March 1991 }
{ aron@garnet.berkeley.edu, aron@ucbgarne.bitnet }
interface
{_______________________________________________________________ }
{ }
{ Instructions to compile an RCMD with Think Pascal }
{ }
{ 1) Open a new project }
{ 2) Remove Runtime.lib }
{ 3) Add DRVRRuntime.lib }
{ 4) Set project type to a Code Resouce under Project->Set Project Type... }
{ 5) You must enter "RCMD" in the Type }
{ 6) You must give an ID such as between 200 and 300 }
{ 7) Set the Attribute to Purgeable }
{ 8) Select Build Code Resource under Project }
{ }
{ That's IT!!! Now copy the RCMD into the WK Procedure source file that will }
{ use the RCMD! }
{_______________________________________________________________ }
{RCMD Structure converted from Think C to Think Pascal by Doug Acker}
{Modified and updated by Robert A. Daniel}
{If you find any errors, please send GEnie mail to B.DANIEL}
type
{Numeric}
{The parameter Long26 is an}
{array of 234 long integers , each containing the current values of the}
{ numeric variables A1% to Z9% in that order . The structure is ordered }
{so that the first 26 elements are A1% through Z1% , the next 26 elements }
{would be A2% through Z2% , and the last}
Long26 = array[1..234] of longint;
UVAR = ^XRec;
XRec = record {Record to the numeric Value of A% to Z%}
x: Long26;
end;
{The parameter VarType is an array of 234 Pascal type strings of 134}
{characters each ( including the length byte ) , containing the current contents of the}
{stringvariables A1$ to Z9$ in that order . The structure is ordered so that}
{ the first 26 elements are A1$ through Z1$ , the next 26 elements would be }
{A2$ through Z2$, and the last 26 elements would be A9$ through Z9$. }
Str134 = string[134];
VarType = array[1..234] of Str134;
USTR = ^yRec;
yRec = record {Record that points to the string of A$ to Z$}
y: VarType;
end;
WKParam = array[1..8350] of byte;
WKPtr = ^WKPtrRec;
WKPtrRec = record {Record that points to XXXPARAM Bytes}
theval: WKParam;
end;
byte20 = array[1..20] of byte;
bytePtr = ^byteRec;
byteRec = record {Record structure for the GETGROUP/SETGROUP and GETBOX/SETBOX}
{procedure commands containing 20bytes}
b: byte20;
end;
Buff1K = array[1..1024] of byte;
Buff1KPtr = ^Buff1Rec;
Buff1Rec = record {1K buffer free to use if free memory isn't known or}
data: Buff1K; {known memory is small}
end;
Buff2K = array[1..2048] of byte;
Buff2KPtr = ^Buff2Rec;
Buff2Rec = record {2K buffer free to use if free memory isn't known or}
data: Buff2K; {know memory is small}
end;
FilterType = array[1..256, 1..2] of byte;
FilterPtr = ^FilterRec;
FilterRec = record {Record to the filters for the terminal/capture/Protocol filters}
{256 ASCII codes, second byte: 0=pass,1=strip, 2=replace, 3=enemuerate}
f: FilterType;
end;
FlagPtr = ^FlagsRec;
FlagsRec = record {Used by the IF YES and IF NO procedure commands, 0=no,1=yes}
{Used by the IF ERROR and IF NO ERROR procedure commands, 0=no, 1=yes}
isyes: byte;
iserr: byte;
end;
PathType = array[1..124] of byte;
PathPtr = ^Byte124;
Byte124 = record {The path to Received File Destination path}
thepath: PathType;
end;
RGBColorRec = record {IM V page 48}
red: integer;
green: integer;
blue: integer;
end;
passvars = record
uservar: UVAR; {A% to Z% array of 26 longint}
userstr: USTR; {A$ to Z$ arrray of 26 Str255}
params1: WKPtr; {values to use with the GETPARAM or PUTPARAM array of 8350 bytes}
reserved1: Handle; {Reserved}
reserved2: longint; {Reserved}
reserved3: longint; {Reserved}
reserved4: longint; {Reserved}
reserved5: integer; {Reserved}
userbl1: ^ParamBlockRec; {IM II-98 I/O using the USERXXXX1 procedure commands}
userbl2: ^ParamBlockRec; {IM II-98 I/O using the USERXXXX2 procedure commands}
pblock: ^ParamBlockRec; {IM II-98 I/O using the Serial In port}
qblock: ^ParamBlockRec; {IM II-98 I/O using the Serial Out port}
radiogroup: bytePtr; {Record structure for the GETGROUP/SETGROUP}
{procedure commands containing 20 bytes}
checkbox: bytePtr; {Record structure for the GETBOX/SETBOX procedure}
{commands containing 20bytes}
buff1K: Buff1KPtr; {1K buffer for own use allocated by WK}
buff2K: Buff2KPtr; {2K buffer for own use allocated by WK}
tfilter: FilterPtr; {Terminal Filter}
ffilter: FilterPtr; {File Capture Filter}
filter: FilterPtr; {Protocol Transfer Filter}
theflags: FlagPtr; {IF YES/NO amd IF ERROR/NO ERROR}
recpath: PathPtr; {Recived File path dest - up to 123 byte string}
forecolor: RGBColorRec; {terminal window foreground}
backcolor: RGBColorRec; {terminal window background}
hilcolor: RGBColorRec; {terminal window hilite}
sbfore: RGBColorRec; {status barforeground}
sbback: RGBColorRec; {status bar background}
sbhil: RGBColorRec; {status bar hilite}
phonefore: RGBColorRec; {phonebook foreground}
phoneback: RGBColorRec; {phonebook background}
phonehil: RGBColorRec; {phoneboox hilite}
indfore: RGBColorRec; {File Transfer Indicator foreground}
indback: RGBColorRec; {File Transfer indicator background}
rlefore: RGBColorRec; {RLE graphics foreground}
rleback: RGBColorRec; {RLE grpahic background}
WKsWindow: WindowPeek; {IM I-304 (WindowPeek/CWindowPeek) ptr to terminal window}
DoUpdate: integer; {If RCMD draws in gp, set to nozero so RR will redraw the term }
{window when RCMD is done }
Transfer: Rect; {IM I-141 last position of file transfer window}
version: integer; {version number of structure, currently = 0}
end;
Rptr = ^passvars; {Pointer to above structure}
{_______________________________________________________________ }
{Main RCMD code}
procedure main (params: Rptr); {pass the pointer to the structure}
implementation
procedure main;
const
{ Elements in the array of White Knight integer variables }
{ from A1% to Z9%: }
position_of_S9% = 227; { (26 * 8) + 19 }
position_of_S8% = 201; { (26 * 7) + 19 }
position_of_S7% = 175; { (26 * 6) + 19 }
type
volClikByteType = byte;
volClikBytePointerType = ^volClikByteType;
var
pointerToPRAMRecord: SysPPtr;
volClikByte: volClikByteType;
volClikBytePointer: volClikBytePointerType;
PRAMErrorReturn: integer;
previousSpeakerVolume: integer;
requestedSpeakerVolume: integer;
{ ----- }
procedure getPRAM;
begin
{ Get a copy of the settings in parameter RAM, and store this copy }
{ in a record structure reflecting the organization of these settings. }
pointerToPRAMRecord := GetSysPPtr;
{ Temporarily store the value of the one-byte portion of }
{ parameter RAM which stores the speaker volume, double-click time, }
{ caret-blink time, and other settings. }
volClikByte := pointerToPRAMRecord^.volClik;
end; { PROCEDURE getPRAM }
{ ----- }
procedure setPRAM (speakerVolume: integer);
begin
{ Offset 5 from the high order bit of the volClikByte is bit 10. }
{ Offset 6 from the high order bit of the volClikByte is bit 9. }
{ Offset 7 from the high order bit of the volClikByte is bit 8. }
with pointerToPRAMRecord^ do
begin
{ Set bits 8-10 (at offsets 5-7) of the volClikByte to reflect }
{ the new requested speaker volume. }
{ This is a hokey way to diddle bits, but it's very clear}
{ and it works. }
case speakerVolume of
7: {111}
begin
bitSet(Ptr(volClikBytePointer), 5);
bitSet(Ptr(volClikBytePointer), 6);
bitSet(Ptr(volClikBytePointer), 7);
end;
6: {110}
begin
bitSet(Ptr(volClikBytePointer), 5);
bitSet(Ptr(volClikBytePointer), 6);
bitClr(Ptr(volClikBytePointer), 7);
end;
5: {101}
begin
bitSet(Ptr(volClikBytePointer), 5);
bitClr(Ptr(volClikBytePointer), 6);
bitSet(Ptr(volClikBytePointer), 7);
end;
4: {100}
begin
bitSet(Ptr(volClikBytePointer), 5);
bitClr(Ptr(volClikBytePointer), 6);
bitClr(Ptr(volClikBytePointer), 7);
end;
3: {011}
begin
bitClr(Ptr(volClikBytePointer), 5);
bitSet(Ptr(volClikBytePointer), 6);
bitSet(Ptr(volClikBytePointer), 7);
end;
2: {010}
begin
bitClr(Ptr(volClikBytePointer), 5);
bitSet(Ptr(volClikBytePointer), 6);
bitClr(Ptr(volClikBytePointer), 7);
end;
1: {001}
begin
bitClr(Ptr(volClikBytePointer), 5);
bitClr(Ptr(volClikBytePointer), 6);
bitSet(Ptr(volClikBytePointer), 7);
end;
0: {000}
begin
bitClr(Ptr(volClikBytePointer), 5);
bitClr(Ptr(volClikBytePointer), 6);
bitClr(Ptr(volClikBytePointer), 7);
end;
end; {case}
end; {with pointerToPRAMRecord^ do}
{ Change the VolClick byte in our memory copy of the parameter RAM }
{ to reflect the changes made to our copy of this byte, above. }
pointerToPRAMRecord^.volClik := volClikBytePointer^;
end; { PROCEDURE setPRAM }
{ ----- }
function writePRAM: integer;
var
OSError: OSErr;
begin
{ Write the pointerToPRAMRecord (of type SysPPtr), containing }
{ the current settings for parameter RAM in low memory, to the}
{ battery-backed parameter RAM in the clock chip. }
OSError := WriteParam;
{ Return the error code from this operation, if any. }
if OSError <> noErr then {noErr is a constant set to 0}
writePRAM := OSError
else
writePRAM := noErr;
end; { FUNCTION writePRAM }
{ ----- }
procedure cleanUp;
begin
disposPtr(Ptr(volClikBytePointer));
disposPtr(Ptr(pointerToPRAMRecord));
end; { PROCEDURE cleanUp }
{ ----- }
begin { PROCEDURE main }
{ Assign the value of S9% to the requested new SpeakerVolume. }
requestedSpeakerVolume := params^.uservar^.x[position_of_S9%];
GetSoundVol(previousSpeakerVolume);
if previousSpeakerVolume = requestedSpeakerVolume then
begin
{return 0 in S7% to indicate success }
params^.uservar^.x[position_of_S7%] := 0;
{ Return the previous sound volume in S8% }
params^.uservar^.x[position_of_S8%] := previousSpeakerVolume;
{ Return without changing the speaker volume. }
exit(main);
end;
{ If the requested speaker volume is outside the valid range }
{ of 0-7, then return -1 in S7% to indicate the speaker volume }
{ could not be changed. }
if (requestedSpeakerVolume < 0) or (requestedSpeakerVolume > 7) then
params^.uservar^.x[position_of_S7%] := -1
else
begin
{ Return the previous sound volume in S8% }
GetSoundVol(previousSpeakerVolume);
params^.uservar^.x[position_of_S8%] := previousSpeakerVolume;
{ Change the sound volume to the value specified in S9% }
SetSoundVol(requestedSpeakerVolume);
{ If the current speaker volume was not changed to the }
{ new volume requested, then return -1 in S7% to indicate failure}
{ and exit without writing anything to parameter RAM (PRAM). }
getSoundVol(previousSpeakerVolume); { actually the current volume }
if previousSpeakerVolume <> requestedSpeakerVolume then
begin
params^.uservar^.x[position_of_S7%] := -1;
exit(main);
end;
{ Write the new speaker volume to PRAM. }
getPRAM;
setPRAM(requestedSpeakerVolume);
PRAMErrorReturn := writePRAM;
{ Return the result code from attempting to write }
{ the new speaker volume to PRAM in S7%. }
{ The result code should be either 0 (success) or -87 (failure). }
params^.uservar^.x[position_of_S7%] := PRAMErrorReturn;
{ Dispose of pointers. }
cleanUp;
end;
end;
end.